package org.jeecg.modules.door.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.door.entity.LwgyEglock;
import org.jeecg.modules.door.entity.LwgyEglockRoomUser;
import org.jeecg.modules.door.mapper.LwgyEglockMapper;
import org.jeecg.modules.door.service.ILwgyEglockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description: 门锁管理
 * @Author: jeecg-boot
 * @Date:   2022-06-15
 * @Version: V1.0
 */
@Service
public class LwgyEglockServiceImpl extends ServiceImpl<LwgyEglockMapper, LwgyEglock> implements ILwgyEglockService {

	@Autowired
	private LwgyEglockMapper lwgyEglockMapper;

	@Override
	public IPage<LwgyEglock> queryPageListCustom(Page<LwgyEglock> page, QueryWrapper<LwgyEglock> queryWrapper) {
/*		queryWrapper.isNotNull("vb.id");
		queryWrapper.orderByAsc("bed_code");*/
		return page.setRecords(lwgyEglockMapper.queryPageListCustom(page,queryWrapper));
	}

	@Override
	public List<LwgyEglockRoomUser> selectUserByRoom(String roomId) {
		List<LwgyEglockRoomUser>  list = new ArrayList<LwgyEglockRoomUser>();
		//查询宿舍中学生
		List<LwgyEglockRoomUser> roomUsers1 = lwgyEglockMapper.selectStudentByRoom(roomId);
		//查询该房间绑定的分组中的人
		List<LwgyEglockRoomUser> roomUsers2 = lwgyEglockMapper.selectGroupUserByRoom(roomId);
		//后期可能会添加管理员绑定等等等等，。。。。。
		list.addAll(roomUsers1);
		list.addAll(roomUsers2);
		return list;
	}

	@Override
	public void updateDoorCodeByRoomId(LwgyEglock lwgyEglock){
		System.out.println(lwgyEglock.getDoorCode());
		System.out.println(lwgyEglock.getRoomId());
		if(oConvertUtils.isNotEmpty(lwgyEglock.getDoorCode()) && oConvertUtils.isNotEmpty(lwgyEglock.getRoomId()) ){
			lwgyEglockMapper.updateDoorCodeByRoomId(lwgyEglock);
		}
	}

	@Override
	public List<LwgyEglock> queryDoorList(LwgyEglock lwgyEglock){

		//未完成，查询导出用门锁数据
		List<LwgyEglock> list = new ArrayList<LwgyEglock>();
		return list;
	}

}
